Imports Microsoft.VisualBasic
Imports System.ComponentModel
Imports System.Collections.Generic

Namespace My
    Public Class MyFormView
        Inherits FormView

        <TypeConverter(GetType(StringArrayConverter)), DefaultValue(GetType(String), Nothing)> _
    Public Property DataNames() As String()
            Get
                If ViewState("DataNames") Is Nothing Then
                    ViewState("DataNames") = New String() {}
                End If

                Return ViewState("DataNames")
            End Get
            Set(ByVal value As String())
                ViewState("DataNames") = value.Clone()

            End Set
        End Property

        <Browsable(False)> _
        Public Property Data() As Dictionary(Of String, Object)
            Get
                If ViewState("Data") Is Nothing Then
                    ViewState("Data") = New Dictionary(Of String, Object)
                End If

                Return ViewState("Data")
            End Get
            Set(ByVal value As Dictionary(Of String, Object))
                ViewState("Data") = value
            End Set
        End Property

        Protected Overrides Sub PerformDataBinding(ByVal data As System.Collections.IEnumerable)
            Me.Data.Clear()

            MyBase.PerformDataBinding(data)
        End Sub

        Protected Overrides Sub OnDataBound(ByVal e As System.EventArgs)

            For Each dataName As String In Me.DataNames
                Me.Data.Add(dataName, DataBinder.Eval(Me.DataItem, dataName))
            Next

            MyBase.OnDataBound(e)
        End Sub

        Public Function FindDDLControl(ByVal id As String) As DropDownList
            Return TryCast(Me.FindControl(id), DropDownList)
        End Function

        Public Function FindTxtControl(ByVal id As String) As TextBox
            Return TryCast(Me.FindControl(id), TextBox)
        End Function

        Public Function FindChkControl(ByVal id As String) As CheckBox
            Return TryCast(Me.FindControl(id), CheckBox)
        End Function

        Public Function FindMyChkControl(ByVal id As String) As MyCheckBox
            Return TryCast(Me.FindControl(id), MyCheckBox)
        End Function

        'Public Function FindCalendarTxtControl(ByVal id As String) As MyCalendarTextBoxBase
        '    Return TryCast(Me.FindControl(id), MyCalendarTextBoxBase)
        'End Function

        Public Function FindMonthlyControl(ByVal id As String) As MonthlyControlBase
            Return TryCast(Me.FindControl(id), MonthlyControlBase)
        End Function

        Public Function FindAnnualControl(ByVal id As String) As AnnualControlBase
            Return TryCast(Me.FindControl(id), AnnualControlBase)
        End Function

        Public Function FindTableDataSourceControl(ByVal id As String) As TableDataSource
            Return TryCast(Me.FindControl(id), TableDataSource)
        End Function

        Public Function FindGVControl(ByVal id As String) As MyGridView
            Return TryCast(Me.FindControl(id), MyGridView)
        End Function
    End Class
End Namespace
